// pages/demand-detail/demand-detail.js
const app = getApp()

const xuqiuTypeMap = {
  care: { text: '医院陪护', color: '#2196f3' },
  errand: { text: '跑腿买药', color: '#e91e63' },
  nursing: { text: '上门护理', color: '#afb42b' }
};
Page({
  data: {
    detail: null,
	xuqiuid:'',
    isAuthorized: false
  },

  onLoad(options) {
	console.log(options.id)
    this.loadData(options.id)
	console.log(options.id)
	this.xuqiuid = options.id
    this.checkAuthStatus()
  },

  // 加载详情数据
  async loadData(id) {
    wx.showLoading({ title: '加载中' })
    this.setData({ isLoading: true });
         	var that = this
			console.log('-----------',id)
               app.util.request({
                       url: 'Xuqiu/detail',
                       data: {
    					   id:id
                       },
                       success(res) {
                               var data = res.data.data;
         					  console.log(data)
                                that.setData({
                                       detail: {
                                         ...data.xuqiu,
                                         typeText: xuqiuTypeMap[data.type]?.text || '其他需求',
                                         typeColor: xuqiuTypeMap[data.type]?.color || '#666'
                                       },
                                       loading: false
                                     });
                       }
               })
  },

  // 图片预览
  previewImage(e) {
    const current = e.currentTarget.dataset.url
    wx.previewImage({
      current,
      urls: [current]
    })
  },


  // 检查认证状态
  checkAuthStatus() {
    // const isAuthorized = app.globalData.userInfo?.certStatus === 2
    // this.setData({ isAuthorized })
  },

  // 跳转认证
  navigateToAuth() {
    wx.navigateTo({
      url: '/pages/user/auth'
    })
  },
  makePhoneCall(e) {
	  console.log(e)
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.phone, // 需要拨打的电话号码
        success: () => {
          console.log("拨打电话成功！");
        },
        fail: (err) => {
          console.error("拨打电话失败：", err);
        }
      });
    }
})